VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "ITGControls.ocx"
Begin VB.Form frmQueryBuilder 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Query Builder"
   ClientHeight    =   8880
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7440
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8880
   ScaleWidth      =   7440
   Begin ITGControls.ITGCommandButton cmdTest 
      Height          =   390
      Left            =   5895
      TabIndex        =   24
      Top             =   7560
      Width           =   1515
      _ExtentX        =   2672
      _ExtentY        =   688
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Test Script"
   End
   Begin VB.PictureBox Picture1 
      BackColor       =   &H8000000C&
      Height          =   4125
      Left            =   30
      ScaleHeight     =   4065
      ScaleWidth      =   7320
      TabIndex        =   6
      Top             =   990
      Width           =   7380
      Begin TabDlg.SSTab SSTab1 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   315
         TabIndex        =   7
         Top             =   225
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":0000
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView1"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView1 
            Height          =   1380
            Left            =   30
            TabIndex        =   8
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab2 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   2025
         TabIndex        =   9
         Top             =   225
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":001C
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView2"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView2 
            Height          =   1380
            Left            =   30
            TabIndex        =   10
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab3 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   3750
         TabIndex        =   11
         Top             =   225
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":0038
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView3"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView3 
            Height          =   1380
            Left            =   30
            TabIndex        =   12
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab4 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   5490
         TabIndex        =   13
         Top             =   225
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":0054
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView4"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView4 
            Height          =   1380
            Left            =   30
            TabIndex        =   14
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab5 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   315
         TabIndex        =   15
         Top             =   2160
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":0070
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView5"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView5 
            Height          =   1380
            Left            =   30
            TabIndex        =   16
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab6 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   2025
         TabIndex        =   17
         Top             =   2160
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":008C
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView6"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView6 
            Height          =   1380
            Left            =   30
            TabIndex        =   18
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab7 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   3750
         TabIndex        =   19
         Top             =   2160
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":00A8
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView7"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView7 
            Height          =   1380
            Left            =   30
            TabIndex        =   20
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
      Begin TabDlg.SSTab SSTab8 
         DragMode        =   1  'Automatic
         Height          =   1695
         Left            =   5490
         TabIndex        =   21
         Top             =   2160
         Visible         =   0   'False
         Width           =   1485
         _ExtentX        =   2619
         _ExtentY        =   2990
         _Version        =   393216
         Tabs            =   1
         TabsPerRow      =   1
         TabHeight       =   520
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TabCaption(0)   =   "Table"
         TabPicture(0)   =   "frmQueryBuilder.frx":00C4
         Tab(0).ControlEnabled=   -1  'True
         Tab(0).Control(0)=   "ListView8"
         Tab(0).Control(0).Enabled=   0   'False
         Tab(0).ControlCount=   1
         Begin MSComctlLib.ListView ListView8 
            Height          =   1380
            Left            =   30
            TabIndex        =   22
            Top             =   285
            Width           =   1425
            _ExtentX        =   2514
            _ExtentY        =   2434
            View            =   3
            LabelEdit       =   1
            LabelWrap       =   -1  'True
            HideSelection   =   -1  'True
            Checkboxes      =   -1  'True
            GridLines       =   -1  'True
            _Version        =   393217
            ForeColor       =   -2147483640
            BackColor       =   -2147483643
            BorderStyle     =   1
            Appearance      =   1
            NumItems        =   1
            BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
               Text            =   "Fields"
               Object.Width           =   1905
            EndProperty
         End
      End
   End
   Begin VB.TextBox txtSQL 
      Appearance      =   0  'Flat
      Height          =   1305
      Left            =   30
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   5
      Text            =   "frmQueryBuilder.frx":00E0
      Top             =   6165
      Width           =   5775
   End
   Begin VB.Frame Frame1 
      Height          =   930
      Left            =   30
      TabIndex        =   2
      Top             =   -15
      Width           =   7365
      Begin ITGControls.ITGTextBox txtSubject 
         Height          =   285
         Left            =   270
         TabIndex        =   3
         Top             =   195
         Width           =   6810
         _ExtentX        =   11800
         _ExtentY        =   503
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Report Name"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1400
         TextBoxWidth    =   5350
      End
      Begin ITGControls.ITGTextBox txtFileName 
         Height          =   285
         Left            =   270
         TabIndex        =   4
         Top             =   525
         Width           =   6810
         _ExtentX        =   11800
         _ExtentY        =   503
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Filename"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1400
         TextBoxWidth    =   5350
      End
   End
   Begin MSDataGridLib.DataGrid dtgResults 
      Height          =   1275
      Left            =   30
      TabIndex        =   0
      Top             =   7545
      Width           =   5805
      _ExtentX        =   10239
      _ExtentY        =   2249
      _Version        =   393216
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ColumnCount     =   1
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   1033
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.ListView lvwJoin 
      Height          =   945
      Left            =   15
      TabIndex        =   1
      Top             =   5160
      Width           =   5820
      _ExtentX        =   10266
      _ExtentY        =   1667
      View            =   3
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   0
      NumItems        =   5
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Table 1"
         Object.Width           =   2152
      EndProperty
      BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   1
         Text            =   "Join"
         Object.Width           =   2293
      EndProperty
      BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   2
         Text            =   "Table 2"
         Object.Width           =   2152
      EndProperty
      BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   3
         Text            =   "Field 1"
         Object.Width           =   1764
      EndProperty
      BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         SubItemIndex    =   4
         Text            =   "Field 2"
         Object.Width           =   1764
      EndProperty
   End
   Begin MSComctlLib.ListView lvwTables 
      Height          =   2325
      Left            =   5865
      TabIndex        =   23
      Top             =   5160
      Width           =   1545
      _ExtentX        =   2725
      _ExtentY        =   4101
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      Checkboxes      =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   0
      NumItems        =   1
      BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
         Text            =   "Tables"
         Object.Width           =   2646
      EndProperty
   End
   Begin ITGControls.ITGCommandButton ITGCommandButton2 
      Height          =   390
      Left            =   5895
      TabIndex        =   25
      Top             =   7980
      Width           =   1515
      _ExtentX        =   2672
      _ExtentY        =   688
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Create SP"
   End
   Begin ITGControls.ITGCommandButton cmdExit 
      Height          =   390
      Left            =   5895
      TabIndex        =   26
      Top             =   8400
      Width           =   1515
      _ExtentX        =   2672
      _ExtentY        =   688
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Exit"
   End
End
Attribute VB_Name = "frmQueryBuilder"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.12.23

Option Explicit

Private connList As ADODB.Connection

'Object variables




'ADO Connection variables

Private connRep As ADODB.Connection

Dim rsRep As ADODB.Recordset

'Other declaration
Public sBit As String
Public tmpSQL As String
Public tmpFields1 As String
Public tmpFields2 As String

Private Sub cmdTest_Click()
On Error GoTo HandleErr
    Set rsRep = New ADODB.Recordset
    OpenNewConnection connRep

    rsRep.CursorLocation = adUseClient
    
    rsRep.Open Trim(txtSQL), _
            connRep, adOpenStatic, adLockBatchOptimistic

    If rsRep.RecordCount < 1 Then
        MsgBox "No Records for your query were found.", vbInformation, "Try New Query."
    Else
        Set dtgResults.DataSource = rsRep
        MsgBox "Query Successful", vbExclamation, "Success"
    End If

HandleErr:
    Select Case err.Number
        Case 0
        Case Else
            MsgBox "Error " & err.Number & ": " & err.Description, vbCritical, "f00_DynamoReport1.cmdConnect_Click" 'ErrorHandler:$$N=f00_DynamoReport1.cmdConnect_Click
    End Select
End Sub

Private Sub cmdExit_Click()
    frmReportWriter.txtRemarks.Text = txtSQL
    Unload Me
End Sub

Private Sub Form_Activate()
    BitVisible ITGLedgerMain.tbrMain
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    Set FrmName = Me
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
 
    tmpSQL = Me.txtSQL.Text
    
    Set frmQueryBuilder = Nothing
    Set connList = Nothing
    Set rsRep = Nothing
    Set connRep = Nothing
    lCloseWindow = True
End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    Set FrmName = Me
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    frmITGSearch.Show
    frmITGSearch.ZOrder
End Sub

Private Sub Form_Load()

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False

    Set FrmName = Me
    
    Dim rsGet As New Recordset

    lvwTables.ListItems.Clear

    sSQL = "SELECT distinct cTable FROM REPTABLE"
    rsGet.Open sSQL, cn, adOpenKeyset, adLockReadOnly
    
    If rsGet.RecordCount <> 0 Then
        While Not rsGet.EOF
            Set itmX = lvwTables.ListItems.Add(, , rsGet!cTable)
            rsGet.MoveNext
        Wend
    End If
    
    rsGet.Close
    Set rsGet = Nothing
    
End Sub

Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    tmpFields1 = ""
    If ListView1.ListItems.Count = 0 Then Exit Sub
    For i = 1 To ListView1.ListItems.Count
        If ListView1.ListItems(i).Checked = True Then
            tmpFields1 = tmpFields1 & "A." & ListView1.ListItems(i) & ", "
        End If
    Next i
    If Trim(tmpFields1) <> "" Then
        tmpFields1 = Mid(tmpFields1, 1, Len(tmpFields1) - 2)
    End If
    UpdateSQL
End Sub

Private Sub ListView2_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    tmpFields2 = ""
    If ListView2.ListItems.Count = 0 Then Exit Sub
    For i = 1 To ListView2.ListItems.Count
        If ListView2.ListItems(i).Checked = True Then
            tmpFields2 = tmpFields2 & "B." & ListView2.ListItems(i) & ", "
        End If
    Next i
    If Trim(tmpFields2) <> "" Then
        tmpFields2 = Mid(tmpFields2, 1, Len(tmpFields2) - 2)
    End If
    UpdateSQL
End Sub

Private Sub lvwTables_ItemCheck(ByVal Item As MSComctlLib.ListItem)
Dim X As Integer
    X = 0
    If lvwTables.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwTables.ListItems.Count
        If lvwTables.ListItems(i).Checked = True Then
            X = X + 1
            If X = 1 Then
                If SSTab1.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView1, SSTab1
                End If
            ElseIf X = 2 Then
                If SSTab2.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView2, SSTab2
                End If
            ElseIf X = 3 Then
                If SSTab3.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView3, SSTab3
                End If
            ElseIf X = 4 Then
                If SSTab4.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView4, SSTab4
                End If
            ElseIf X = 5 Then
                If SSTab5.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView5, SSTab5
                End If
            ElseIf X = 6 Then
                If SSTab6.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView6, SSTab6
                End If
            ElseIf X = 7 Then
                If SSTab7.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView7, SSTab7
                End If
            ElseIf X = 8 Then
                If SSTab8.Caption <> lvwTables.ListItems(i) Then
                    FillMeUp lvwTables.ListItems(i) & "", ListView8, SSTab8
                End If
            End If
        End If
    Next i
    If X = 0 Then
        SSTab1.Visible = False
        SSTab1.Caption = "Table"
    ElseIf X = 1 Then
        SSTab2.Visible = False
        SSTab2.Caption = "Table"
    ElseIf X = 2 Then
        SSTab3.Visible = False
        SSTab3.Caption = "Table"
    ElseIf X = 3 Then
        SSTab4.Visible = False
        SSTab4.Caption = "Table"
    ElseIf X = 4 Then
        SSTab5.Visible = False
        SSTab5.Caption = "Table"
    ElseIf X = 5 Then
        SSTab6.Visible = False
        SSTab6.Caption = "Table"
    ElseIf X = 6 Then
        SSTab7.Visible = False
        SSTab7.Caption = "Table"
    ElseIf X = 7 Then
        SSTab8.Visible = False
        SSTab8.Caption = "Table"
    End If
    UpdateSQL
End Sub

Sub FillMeUp(tmpTable As String, lvw As ListView, tbb As SSTab)
Dim rsFill As New Recordset
    'If tbb.Caption <> "Table" Then Exit Sub
    'If tbb.Caption = tmpTable Then Exit Sub
    tbb.Visible = True
    tbb.Caption = tmpTable
    
    sSQL = "SELECT * FROM REPTABLE WHERE cTable = '" & tmpTable & "'"
    
    lvw.ListItems.Clear
    
    rsFill.Open sSQL, cn, adOpenKeyset, adLockReadOnly
    
    If rsFill.RecordCount <> 0 Then
        While Not rsFill.EOF
            Set itmX = lvw.ListItems.Add(, , rsFill!cFields)
            rsFill.MoveNext
        Wend
    End If
    
    rsFill.Close
    Set rsFill = Nothing
    
End Sub

Sub UpdateSQL()
Dim X As Integer
    X = 0
    If lvwTables.ListItems.Count = 0 Then Exit Sub
    For i = 1 To lvwTables.ListItems.Count
        If lvwTables.ListItems(i).Checked = True Then
            X = X + 1
        End If
    Next i
    If X = 0 Then
        txtSQL.Text = "Select * From <Table>"
    ElseIf X = 1 Then
        txtSQL.Text = "Select " & IIf(tmpFields1 = "", "*", tmpFields1) & " From " & SSTab1.Caption & " A "
    ElseIf X = 2 Then
        txtSQL.Text = "Select " & IIf(tmpFields1 = "", "A.*", tmpFields1) & ", " & IIf(tmpFields2 = "", "B.*", tmpFields2) & " From " & SSTab1.Caption & " A Cross Join " & _
                       SSTab2.Caption & " B "
        lvwJoin.ListItems.Clear
        Set itmX = lvwJoin.ListItems.Add(, , SSTab1.Caption)
        itmX.SubItems(1) = "Cross Join"
        itmX.SubItems(2) = SSTab2.Caption
    ElseIf X = 3 Then
    txtSQL.Text = "Select " & IIf(tmpFields1 = "", "A.*", tmpFields1) & " From " & SSTab1.Caption & " A Cross Join " & _
                       SSTab2.Caption & " B "
    End If
End Sub



